Site Health: Fix false negative in opcode cache test for file cache mode#12185
Site Health: Fix false negative in opcode cache test for file cache mode#12185westonruter wants to merge 3 commits into
Conversation
…ode. The Site Health opcode cache test relied solely on `opcache_get_status()` to determine whether OPcache is active. However, that function returns `false` when OPcache operates in file cache only mode (`opcache.file_cache_only=1`), even though opcode caching is active. As a result, Site Health incorrectly reported "Opcode cache is not enabled" on such configurations. Detection now checks whether the Zend OPcache extension is loaded and `opcache.enable` is on, treating that as sufficient, and only defers to `opcache_get_status()` as authoritative when it returns usable data. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Hi there! 👋 Thank you for your contribution to WordPress! 💖 It looks like this is your first pull request to No one monitors this repository for new pull requests. Pull requests must be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. Pull requests are never merged on GitHub. The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making. More information about how GitHub pull requests can be used to contribute to WordPress can be found in the Core Handbook. Please include automated tests. Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the Automated Testing page in the handbook. If you have not had a chance, please review the Contribute with Code page in the WordPress Core Handbook. The Developer Hub also documents the various coding standards that are followed:
Thank you, |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
Does |
The test recomputed its own expectation using the previous detection logic that relied solely on opcache_get_status(). Update it to mirror the new detection (extension loaded and opcache.enable on, deferring to opcache_get_status() only when it returns usable data) so the expected status matches the production result in file cache only and CLI environments. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
… mode. The Site Health Info debug data reported the opcode cache as "Disabled by configuration" whenever opcache_get_status() returned false. That happens in file cache only mode (opcache.file_cache_only=1) and when the function is listed in disable_functions, even though OPcache is active. Detection now reports the cache as enabled when the Zend OPcache extension is loaded and opcache.enable is on but opcache_get_status() returns no usable data. The detailed statistics (memory usage, hit rate, etc.) remain gated on a successful opcache_get_status() call, since that data is only available for the shared memory cache. Co-Authored-By: siliconforks <siliconforks@git.wordpress.org> Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@siliconforks Good point. How about 030690d? |
Description
WordPress 7.0 introduced a Site Health test for the PHP opcode cache (
WP_Site_Health::get_test_opcode_cache(), added in [r61612] / Core-63697). The test detects whether OPcache is active by callingopcache_get_status().However,
opcache_get_status()only reports on the shared memory cache. When OPcache is configured for file cache only mode (opcache.file_cache_only=1, used where shared memory is unavailable or disabled),opcache_get_status()returnsfalseeven though opcode caching is fully active. Per the PHP manual, it will not return any information about the file cache.As a result, Site Health incorrectly reports "Opcode cache is not enabled" on file-cache-only setups — a false negative affecting released 7.0 sites.
Fix
Detection no longer relies solely on
opcache_get_status(). It now checks whether the Zend OPcache extension is loaded andopcache.enableis on, treating that as sufficient, and only defers toopcache_get_status()as authoritative when it returns usable data.file_cache_only=1)opcache.enable=0This also covers the case where
opcache_get_status()is listed indisable_functions:function_exists()returnsfalse, so the result falls back to the extension/INI check rather than reporting a false negative.Trac ticket: https://core.trac.wordpress.org/ticket/64707
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 4.8
Used for: Investigating the Trac ticket and root cause, drafting the detection fix, and the PR description. The implementation was reviewed with PHPCS and PHPStan level 10 static analysis verified.